import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.util.*;

/**
 * Level_Zero 类用于创建不同位置的Block对象。
 */
public class Level_Zero extends Levels
{
    public ArrayList<Block> blocks;
    public Door door;
    public Snake snake;
    public boolean canLeave = false;
    public Level_Zero()
    {
        super(750, 750);
        blocks = new ArrayList<Block>();
        Greenfoot.setSpeed(35);
        CreatBlocks();
        door = new Door();
        snake = new Snake(this);
        addObject(snake, 30, 30);
        addObject(door,280,310);
        addObject(new Button_back(), 30, 50);
        addObject(new FoodClone(),52,533);
        addObject(new FoodClone(),256,540);
        addObject(new FoodClone(),248,678);
        addObject(new FoodClone(),283,371);
        addObject(new FoodClone(),304,134);
        addObject(new FoodClone(),441,226);
        addObject(new FoodClone(),487,542);
        addObject(new FoodClone(),620,240);
        addObject(new FoodClone(),671,536);
    }
    public void act()
    {
        if(snake.getLength()==10)
        {
            canLeave = true;
        }
        if(canLeave&&snake.isTouchingDoor())
        {
            door.Win();
            Greenfoot.playSound("win.wav");
        }
    }
    public void CreatBlocks()
    {
        // 在 (100,75) 到 (290,75) 创建8个Block
        for (int i = 0; i < 9; i++) {
            int x = 100 + i * 25;  // 水平间隔27
            int y = 75;
            Block block = new Block();
            blocks.add(block);
            addObject(block, x, y);
        }

        // 在 (100,185) 到 (290,185) 创建8个Block
        for (int i = 0; i < 9; i++) {
            int x = 100 + i * 25;  // 水平间隔27
            int y = 185;
            Block block = new Block();
            blocks.add(block);
            addObject(block, x, y);
        }

        // 在 (145,185) 到 (145,335) 创建7个Block
        for (int i = 0; i < 7; i++) {
            int x = 145;
            int y = 185 + i * 25;  // 垂直间隔25
            Block block = new Block();
            blocks.add(block);
            addObject(block, x, y);
        }
        // 在 (145,445) 到 (145,655) 创建6个Block
        for (int i = 0; i < 9; i++) {
            int x = 145;
            int y = 445 + i * 25;  // 垂直间隔42（210 / 5）
            Block block = new Block();
            blocks.add(block);
            addObject(block, x, y);
        }
        // 在 (145,445) 到 (270,445) 创建6个Block，间隔为25
        for (int i = 0; i < 6; i++) {
            int x = 145 + i * 25;  // 水平间隔25
            int y = 445;
            Block block = new Block();
            blocks.add(block);
            addObject(block, x, y);
        }
        // 在 (370,420) 到 (420,470) 填满 3x3 网格
        for (int i = 0; i < 3; i++) {
            for (int j = 0; j < 3; j++) {
                int x = 370 + i * 25;  // 横坐标间隔25
                int y = 420 + j * 25;  // 纵坐标间隔25
                Block block = new Block();
                blocks.add(block);
                addObject(block, x, y);
            }
        }
        
        // 在 (550,420) 到 (600,470) 填满 3x3 网格
        for (int i = 0; i < 3; i++) {
            for (int j = 0; j < 3; j++) {
                int x = 550 + i * 25;  // 横坐标间隔25
                int y = 420 + j * 25;  // 纵坐标间隔25
                Block block = new Block();
                blocks.add(block);
                addObject(block, x, y);
            }
        }

        // 在 (370,600) 到 (420,650) 填满 3x3 网格
        for (int i = 0; i < 3; i++) {
            for (int j = 0; j < 3; j++) {
                int x = 370 + i * 25;  // 横坐标间隔25
                int y = 600 + j * 25;  // 纵坐标加180后，间隔25
                Block block = new Block();
                blocks.add(block);
                addObject(block, x, y);
            }
        }
        
        // 在 (550,600) 到 (600,650) 填满 3x3 网格
        for (int i = 0; i < 3; i++) {
            for (int j = 0; j < 3; j++) {
                int x = 550 + i * 25;  // 横坐标间隔25
                int y = 600 + j * 25;  // 纵坐标加180后，间隔25
                Block block = new Block();
                blocks.add(block);
                addObject(block, x, y);
            }
        }
        // 在 (530,75) 到 (530,280) 创建9个Block，间隔为25
        for (int i = 0; i < 9; i++) {
            int x = 530;
            int y = 75 + i * 25;  // 纵坐标间隔25
            Block block = new Block();
            blocks.add(block);
            addObject(block, x, y);
        }
        // 在 (530,175) 到 (670,175) 创建6个Block，间隔为25
        for (int i = 0; i < 6; i++) {
            int x = 530 + i * 25;  // 水平间隔25
            int y = 175;
            Block block = new Block();
            blocks.add(block);
            addObject(block, x, y);
        }

    }
}
